from rest_framework import serializers
from users.models import User  ##


class AdminSerializers(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'

    def create(self, validated_data):
        instance = super().create(validated_data)

        instance.is_staff = True
        instance.set_password(validated_data.get('password'))
        # instance.set_password(instance.password)
        instance.save()

        return instance

    def update(self, instance, validated_data):
        instance=super().update(instance, validated_data)

        # instance.set_password(instance.password)
        instance.set_password(validated_data.get('password'))
        instance.save()

        return instance
